package wnhz.com.business.freeshop.activity.fourthfree;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import wnhz.com.business.R;
import wnhz.com.business.base.BaseFragment;
import wnhz.com.business.base.BaseRecyclerAdapter;
import wnhz.com.business.groupshop.adapter.FragmentFourAdapter;
import wnhz.com.business.groupshop.bean.OrderBean;
import wnhz.com.business.uitls.decoration.HorizDecoration;

public class OrderFourFragment extends BaseFragment implements BaseRecyclerAdapter.OnDataLoadFinish {

    @BindView(R.id.recycler_View)
    RecyclerView recyclerView;
    @BindView(R.id.empty_layout)
    LinearLayout layEmtpy;
    @BindView(R.id.tv_msg)
    TextView tv_msg;

    private FragmentFourAdapter fragmentOneAdapter;
    private List<OrderBean.InfoBean> orderInfos = new ArrayList<>();

    public static OrderFourFragment getInstance() {
        OrderFourFragment sf = new OrderFourFragment();
        return sf;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View rootview = inflater.inflate(R.layout.order_one_fragment, null);
        ButterKnife.bind(this, rootview);
        initView();
        return rootview;
    }

    private void initView() {
        fragmentOneAdapter = new FragmentFourAdapter(getContext(), orderInfos);
        recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
        recyclerView.addItemDecoration(new HorizDecoration(20));
        fragmentOneAdapter.setOnDataLoadFinish(this);
        fragmentOneAdapter.loadDataFirstTime();
        recyclerView.setAdapter(fragmentOneAdapter);
    }

    @Override
    public void loadDataFinished(int datasLength) {
        if (datasLength == 0) {
            layEmtpy.setVisibility(View.VISIBLE);
            tv_msg.setText("暂无订单~");
            recyclerView.setVisibility(View.GONE);
        } else {
            layEmtpy.setVisibility(View.GONE);
        }
    }
}